import cn.itcast.dao.ClassesDao;
import cn.itcast.domain.Classes;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class 测试学生班级 {

    @Test
    public void testFindAll()throws Exception{
        /*1.读取配置文件并创建SqlSessionFactory*/
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);

        /*2.获取sqlSession[这是mybatis的重要API, 使用它可以操作数据库crud*/
        SqlSession sqlSession = sqlSessionFactory.openSession();

        /*3.由Mybatis框架创建UserDao的实现类对象，我们称为代理对象*/
        ClassesDao classesDao = sqlSession.getMapper(ClassesDao.class);

        /*4.查询所有班级*/
        List<Classes> classes = classesDao.findAll();

        /*5.释放资源*/
        sqlSession.close();

        //测试结果
        System.out.println(classes);
    }
}
